package com.wisn.appcheckmethod.plugin;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.content.ContentResolver;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;


public class MainActivity extends AppCompatActivity {
    Button bt_android;
    Button bt_applist;
    Button bt_mac;
    Button bt_imei;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bt_android = findViewById(R.id.bt_android);
        bt_mac = findViewById(R.id.bt_mac);
        bt_imei = findViewById(R.id.bt_imei);
        bt_applist = findViewById(R.id.bt_applist);
        bt_android.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ContentResolver contentResolver = getApplicationContext().getContentResolver();
                String androidId = Settings.System.getString(contentResolver, Settings.Secure.ANDROID_ID);
                bt_android.setText("值：" + androidId);
            }
        });

        bt_applist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DeUtil.isPackageAvailable(MainActivity.this, "com.weixin");
            }
        });
        bt_mac.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                String ipAddress = DeUtil.getIPAddress(true);
//            DeviceUtil.getIPAddress(this)
                try {
                    WifiManager wifiManager = (WifiManager) MainActivity.this.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
                    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
                    String macAddress = wifiInfo.getMacAddress();
                    bt_mac.setText("mac地址："+macAddress);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        bt_imei.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DeUtil.getDeviceId(MainActivity.this);
            }
        });
        findViewById(R.id.bt_hook).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                HookMacAddressUtils.INSTANCE.hookMacAddress(getApplicationContext());
            }
        });
        findViewById(R.id.cancel_hook).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                HookMacAddressUtils.INSTANCE.closeHookMacAddress();

            }
        });
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE,Manifest.permission.ACCESS_NETWORK_STATE},100);
        }
    }
}